package com.jinxin.platform.cdacscontrolmgr.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdacscontrolmgr.bean.CdsideparkmgrParkRecord;
import com.jinxin.platform.cdacscontrolmgr.mapper.CdacscontrolmgrParkRecordMapper;
import com.jinxin.platform.cdacscontrolmgr.service.ICdacscontrolmgrParkRecordService;
import com.jinxin.platform.cdacscontrolmgr.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-18
 * @Author: Lingnan
 **/
@Service
public class CdacscontrolmgrParkRecordServiceImpl implements ICdacscontrolmgrParkRecordService {
    @Autowired
    private CdacscontrolmgrParkRecordMapper cdacscontrolmgrParkRecordMapper;
    @Resource
    private IdWorker idWorker;

    @Override
    public CdsideparkmgrParkRecord selectOne(HashMap param) {
        return cdacscontrolmgrParkRecordMapper.selectOne(param);
    }

    @Override
    public List<CdsideparkmgrParkRecord> list(HashMap param) {
        return cdacscontrolmgrParkRecordMapper.list(param);
    }

    @Override
    public List<CdsideparkmgrParkRecord> listPage(HashMap param) {
        return cdacscontrolmgrParkRecordMapper.listPage(param);
    }

    @Override
    public int listPageCount(HashMap param) {
        return cdacscontrolmgrParkRecordMapper.listPageCount(param);
    }

    @Override
    public JsonResult saveOrUpdate(CdsideparkmgrParkRecord record) {
        if (record == null){
            return JsonResult.error("参数错误，操作失败");
        }
        String id = record.getId();
        int count;
        String msg = "";
        if(StringUtils.isEmpty(id)){
            record.setId(String.valueOf(idWorker.nextId()));
            count = cdacscontrolmgrParkRecordMapper.insert(record);
            msg = "新增成功";
        }else {
            count = cdacscontrolmgrParkRecordMapper.updateByKey(record);
            msg = "更新成功";
        }
        if(count > 0){
            return JsonResult.ok(msg,"");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }

    @Override
    public JsonResult delete(String id) {
        if(StringUtils.isEmpty(id)){
            return JsonResult.error("Id不存在");
        }
        int result = cdacscontrolmgrParkRecordMapper.deleteByKey(id);
        if(result > 0){
            return JsonResult.ok("删除成功","");
        }
        return JsonResult.error("删除失败");
    }

    @Override
    public List<String> listAreaOptions(String projectId) {
        return cdacscontrolmgrParkRecordMapper.listAreaOptions(projectId);
    }

    @Override
    public List<String> listStallOptions(String projectId) {
        return cdacscontrolmgrParkRecordMapper.listStallOptions(projectId);
    }

}
